package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.BdAccLoanTempDao;
import com.fdb.efp.nls.service.domain.BdAccLoanTemp;
import com.fdb.efp.nls.service.facade.BdAccLoanTempService;
import com.fdb.efp.nls.service.vo.BdAccLoanTempVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 * ServiceImpl: 百度借据信息临时表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-04
 */
@Service("bdAccLoanTempService")
public class BdAccLoanTempServiceImpl implements BdAccLoanTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdAccLoanTempServiceImpl.class);

	@Autowired
	private BdAccLoanTempDao bdAccLoanTempDao;

	/**
	 * 新增操作
	 */
	public int insertBdAccLoanTemp(BdAccLoanTempVO inBdAccLoanTempVo) {
		logger.debug("当前新增数据为:" + inBdAccLoanTempVo.toString());
		int num = 0;
		try {
			BdAccLoanTemp bdAccLoanTemp = new BdAccLoanTemp();
			beanCopy(inBdAccLoanTempVo, bdAccLoanTemp);
			num = bdAccLoanTempDao.insertBdAccLoanTemp(bdAccLoanTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdAccLoanTempVO inBdAccLoanTempVo) {
		logger.debug("当前删除数据条件为:" + inBdAccLoanTempVo);
		int num = 0;
		try {
			BdAccLoanTemp bdAccLoanTemp = new BdAccLoanTemp();
			beanCopy(inBdAccLoanTempVo, bdAccLoanTemp);
			num = bdAccLoanTempDao.deleteByPk(bdAccLoanTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdAccLoanTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(BdAccLoanTempVO inBdAccLoanTempVo) {
		logger.debug("当前修改数据为:" + inBdAccLoanTempVo.toString());
		int num = 0;
		try {
			BdAccLoanTemp bdAccLoanTemp = new BdAccLoanTemp();
			beanCopy(inBdAccLoanTempVo, bdAccLoanTemp);
			num = bdAccLoanTempDao.updateByPk(bdAccLoanTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdAccLoanTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public BdAccLoanTempVO queryByPk(BdAccLoanTempVO inBdAccLoanTempVo) {

		logger.debug("当前查询参数信息为:" + inBdAccLoanTempVo);
		try {
			BdAccLoanTemp queryBdAccLoanTemp = new BdAccLoanTemp();
			beanCopy(inBdAccLoanTempVo, queryBdAccLoanTemp);
			BdAccLoanTemp queryRslBdAccLoanTemp = bdAccLoanTempDao.queryByPk(queryBdAccLoanTemp);
			if (Objects.nonNull(queryRslBdAccLoanTemp)) {
				BdAccLoanTempVO outBdAccLoanTempVo = beanCopy(queryRslBdAccLoanTemp, new BdAccLoanTempVO());
				logger.debug("当前查询结果为:" + outBdAccLoanTempVo.toString());
				return outBdAccLoanTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLoanTempVO> queryAll(BdAccLoanTempVO bdAccLoanTempVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdAccLoanTempVO> list = null;
		try {
			List<BdAccLoanTemp> bdAccLoanTemps = bdAccLoanTempDao.queryAllByPage(bdAccLoanTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdAccLoanTemps.size());
			pageSet(bdAccLoanTemps, bdAccLoanTempVo);
			list = (List<BdAccLoanTempVO>) beansCopy(bdAccLoanTemps, BdAccLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLoanTempVO> queryAllCurrOrg(BdAccLoanTempVO bdAccLoanTempVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdAccLoanTemp> bdAccLoanTemps = bdAccLoanTempDao.queryAllCurrOrgByPage(bdAccLoanTempVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + bdAccLoanTemps.size());
		List<BdAccLoanTempVO> list = null;
		try {
			pageSet(bdAccLoanTemps, bdAccLoanTempVo);
			list = (List<BdAccLoanTempVO>) beansCopy(bdAccLoanTemps, BdAccLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLoanTempVO> queryAllCurrDownOrg(BdAccLoanTempVO bdAccLoanTempVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdAccLoanTemp> bdAccLoanTemps = bdAccLoanTempDao.queryAllCurrDownOrgByPage(bdAccLoanTempVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + bdAccLoanTemps.size());
		List<BdAccLoanTempVO> list = null;
		try {
			pageSet(bdAccLoanTemps, bdAccLoanTempVo);
			list = (List<BdAccLoanTempVO>) beansCopy(bdAccLoanTemps, BdAccLoanTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
	
	/**
	 * 
	 * 分页查询【借据临时表】 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:04:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:04
	 * @date 2019年3月23日 下午12:11:04
	 * @version 0.1
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<BdAccLoanTempVO> queryByPage(BdAccLoanTempVO bdAccLoanTempVO) {
		String msg1 = "分页查询借据临时表";
		logger.debug(msg1, "message {}");
		List<BdAccLoanTempVO> list = null;
		try {
			List<BdAccLoanTemp> BdAccLoanTemps = bdAccLoanTempDao.queryByPage(bdAccLoanTempVO);
			list = (List<BdAccLoanTempVO>) beansCopy(BdAccLoanTemps, BdAccLoanTempVO.class);

		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);

		}
		if(list != null) {
			String msg2 = "查询的数据为大小为 " + list.size();
			logger.debug(msg2, "message {}");
		}
		return list;
	}

	/**
	 * 
	 * 统计【借据临时表】数据量 <br>
	 * 0.1:ludayong:2019年3月23日 下午12:11:10:新增 <br>
	 * 
	 * @author ludayong
	 * @since 2019年3月23日 下午12:11:10
	 * @date 2019年3月23日 下午12:11:10
	 * @version 0.1
	 */
	@Override
	public int queryCount() {
		String msg1 = "查询【借据临时表】表中数据量大小";
		logger.debug(msg1, "message {}");
		int num = 0;
		try {
			num = bdAccLoanTempDao.queryCount();
		} catch (Exception e) {
			String msg2 = "查询【借据临时表】表中数据量大小出错" + e;
			logger.debug(msg2, "message {}");
			num = -1;
		}
		return num;
	}
}
